package com.huatai.exchange.bootup.listener;

import com.faneui.common.bean.BaseResp;
import com.faneui.service.Env;
import com.huatai.exchange.service.ClearHisDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "clearhisdataandfile")
@Api("任务")
public class AutoClearHisDataListener {

    private static final Logger logger = LoggerFactory.getLogger(AutoClearHisDataListener.class);

    @Autowired
    private ClearHisDataService clearHisDataService;

    @Autowired
    private Env env;

    @ApiModelProperty("自动清理历史数据文件任务")
    @RequestMapping(value = "", method = RequestMethod.GET)
    @ResponseBody
    public BaseResp run(@RequestParam(required = false) String occurDate) {
        if(!env.isProd()) {
            return new BaseResp();
        }
        logger.info("自动清理历史数据文件任务开始");
        BaseResp resp = new BaseResp();
        try {
            clearHisDataService.clearHisDataRecord();
        } catch (Exception ex) {
            logger.error("", ex);
            resp.setSuccess(false);
            resp.setMsg(ex.getMessage());
        }
        logger.info("自动清理历史数据文件任务结束");
        return resp;
    }

}
